#### "International Relations Scholars, the Media, and the Dilemma of Consensus"
#### Irene Entringer Garcia Blanes, Shauna N. Gillooly, Susan Peterson, Ryan Powers, Michael J. Tierney
#### Replication materials  
#### 3 February 2025
setwd("~/Downloads/Dilemma of Consensus - Submission Documents/Replication file")

# Packages ----------------------------------------------------------------

library(tidyverse)
library(ggplot2)
library(stargazer)
library("wesanderson")
library(RColorBrewer)
library(janitor)

# Reading in Data ---------------------------------------------------------

# Add your working directory here

# Load files
jdata=read.csv("ReplicationFile/Journalist2019SurveyData.csv",na.strings=c("", "NA"), header = TRUE)
pdata<-read.csv("ReplicationFile/Policymaker2017SurveyData.csv",na.strings=c("", "NA"), header = TRUE)
demo=read.csv("ReplicationFile/JournalistDemo_replication.csv",na.strings=c("", "NA"), header = TRUE)

# Functions and themes

printtable <- function(data,caption,digits = NULL) {
  print(xtable(data,auto=TRUE,digits = 1, caption =caption),caption.placement = 'bottom',scalebox = ".78",digits=digits)
}

pctgroup <- function(data,...,rd = 1) {
  select(data,...) %>%
    filter(complete.cases(.)) %>%
    group_by(...) %>%
    summarise(n = n()) %>%
    mutate(Percentage = round(100*n/sum(n),rd))
}

plot_theme = theme(text = element_text(size=12),  
                   panel.grid.major.y = element_blank(), 
                   panel.grid.major.x = element_blank(), 
                   panel.grid.minor.y = element_blank(), 
                   panel.grid.minor.x = element_blank(), 
                   panel.background = element_blank(),
                   plot.background = element_rect(fill = "white",colour = NA),
                   axis.text = element_text(color="black"),
                   axis.line = element_line(colour = "black"),
                   strip.text.y = element_text(angle = 0), axis.title.y = element_text(angle=0, hjust=.5, vjust=.5),
                   axis.title = element_text(lineheight=1.1), 
                   #axis.text.x = element_text(angle = 45, hjust = 1),
                   legend.position = 'none',#removing legend
                   panel.grid.minor = element_blank(),
                   #strip.background = element_blank()
                   # panel.border = element_blank(), axis.line = element_line(),
                   plot.caption = element_text(hjust = 0, face = "italic", size=8, family="Times New Roman")
) 

# 1. Table 1: Demographic characteristics of respondents -----------------------------------------------------

  ## Gender
gender_table <- demo %>%
  filter(Gender != "") %>%
  group_by(Gender) %>%
  summarise(
    gender_pop   = n(),
    gender_sample = sum(survey == 1), 
    .groups      = "drop"
  ) %>%
  mutate(
    PercentagePop    = round(100 * gender_pop / sum(gender_pop), 2),
    PercentageSample = round(100 * gender_sample / sum(gender_sample), 2)
  ) %>%
  select(-Gender)

gender_chisq <- demo %>%
  filter(Gender != "") %>%
  group_by(Gender) %>%
  summarise(
    Population = n(),
    Survey = sum(survey == 1),  
    .groups = "drop"
  )

chisq_gender_result <- chisq.test(as.matrix(gender_chisq %>% select(Survey, Population)))
print(chisq_gender_result)

  ## Age

age_summary_pop <- demo %>% 
  filter(age != "") %>% 
  summarize(
    mean   = round(mean(age, na.rm = TRUE), 2),
    sd     = sd(age, na.rm = TRUE),
    median = median(age, na.rm = TRUE),
    n      = n(),
    se     = sd / sqrt(n)
  ) %>% 
  mutate(Type = 'Population')

age_summary_sample <- demo %>% 
  filter(survey == 1, age != "") %>% 
  summarize(
    mean   = round(mean(age, na.rm = TRUE), 2),
    sd     = sd(age, na.rm = TRUE),
    median = median(age, na.rm = TRUE),
    n      = n(),
    se     = sd / sqrt(n)
  ) %>% 
  mutate(Type = 'Sample')

pop_ages <- demo %>% 
  filter(age != "") %>%  
  pull(age)

sample_ages <- demo %>% 
  filter(survey == 1, age != "") %>% 
  pull(age)

ks_test_result <- ks.test(sample_ages, pop_ages)
print(ks_test_result)

  ## Education Level

education_table <- demo %>%
  filter(HighestDegree != "") %>%
  group_by(HighestDegree) %>%
  summarise(
    edu_pop   = n(),
    edu_sample = sum(survey == 1), 
    .groups      = "drop"
  ) %>%
  mutate(
    PercentagePop    = round(100 * edu_pop / sum(edu_pop), 2),
    PercentageSample = round(100 * edu_sample / sum(edu_sample), 2)
  ) %>%
  select(-HighestDegree)

education_chisq <- demo %>%
  filter(HighestDegree != "") %>%
  group_by(HighestDegree) %>%
  summarise(
    Population = n(),
    Survey = sum(survey == 1),  
    .groups = "drop"
  )

chisq_edu_result <- chisq.test(as.matrix(education_chisq %>% select(Survey, Population)))
print(chisq_edu_result)

# 2. Figure 1: Frequency of engagement with IR knowledge, policymakers and journalists ----------------------------------------------

pdata$Q11[pdata$Q11==""]<-NA
jdata$Q12[jdata$Q12==""]<-NA
jdata$Q9[jdata$Q9==""]<-NA

engage<-rbind(data.frame(round(prop.table(table(jdata$Q9))*100,1),"field"="Journalists\n(social science)"),
              data.frame(round(prop.table(table(jdata$Q12))*100,1),"field"="Journalists\n(international relations)"),
              data.frame(round(prop.table(table(pdata$Q11))*100,1),"field"="Policymakers\n(social science)"))
names(engage)<-c("Frequency","Percentage","Field")         
engage<-engage[engage$Frequency!="",]

engage$Frequency<- fct_relevel(engage$Frequency, "Never", "A few times a year", "A few times a month","A few times a week","Daily")

engage_plot<-ggplot(engage, aes(Frequency,Percentage,fill=Frequency)) +
  geom_bar(stat="identity", color="black") + 
  geom_text(aes(label=Percentage),position = position_dodge(width = 0.7),hjust =-.10,size = 3.5, color = "black") + 
  facet_grid(Field ~.) +
  scale_fill_grey(start = 0, end = 0.8) +  
  scale_y_continuous(expand=c(0,0),limits=c(-.3,34)) +
  xlab("") +
  coord_flip() +
  plot_theme  
ggsave("ReplicationFile/Tierney_Figure1.png",engage_plot,dpi=300,width=7,height=4)


# 3. Figure 2: How useful are the arguments and evidence used in the following disciplines? ----------------------------------------------

jdisciplines <- select(jdata,starts_with("Q33_")) %>%
  gather(Question,Response,Q33_1:Q33_12) %>%
  filter(Response!="") %>% 
  mutate(Response = recode(Response,"Very useful" = "Useful",
                           "Somewhat useful" = "Useful",
                           "Not very useful" = "Not useful",
                           "Not useful at all" = "Not useful")) %>%
  mutate(Question_text = recode(Question,"Q33_1" = "Economics",
                                "Q33_2" = "Political Science",
                                "Q33_3"= "Sociology",
                                "Q33_4"= "Anthropology",
                                "Q33_5"="Psychology",
                                "Q33_6"="Public Policy",
                                "Q33_7"= "International Affairs",
                                "Q33_8"="Area Studies",
                                "Q33_9"= "History",
                                "Q33_10"= "Law",
                                "Q33_11"= "Business",
                                "Q33_12"= "Natural, Physical, Biological, or Computational Sciences"))

jdisciplines<-data.frame(round(prop.table(table(jdisciplines$Response,jdisciplines$Question_text),2)*100,1))
names(jdisciplines)<-c("Response","Question_text","Percentage")
jdisciplines$Response <- factor(jdisciplines$Response, c("Not useful","Useful"))
jdisciplines$Role<-"Journalist"

j_disciplines_plot <- ggplot(jdisciplines, aes(Question_text, Percentage, fill=Response)) +
  geom_bar(stat="identity", position = "stack", color = "black") +  
  plot_theme + coord_flip() + xlab("") +
  scale_y_continuous(limits=c(-10,103),expand=c(0,0)) +
  guides(fill = guide_legend(reverse=TRUE))+
  geom_text(aes(label = Percentage, color=factor(Response)), 
            position = position_stack(vjust = 0.5), size = 3.5,
            show.legend = FALSE) + 
  scale_fill_grey(start = 0, end = 0.8) + 
  scale_color_manual(values = c("white", "black")) +
  plot_theme +
  theme(legend.position="bottom")
j_disciplines_plot
ggsave("ReplicationFile/Tierney_Figure2.png", j_disciplines_plot,dpi=300, width=10, height=8)

# 4. Figure 3: Responses to “At which stage of the writing process are you likely to seek out academic research” ----------------------------------------------

d1 <- separate(jdata,Q17,c("Choice1","Choice2","Choice3","Choice4","Choice5","Choice6","Choice7","Choice8","Choice9"),sep = ",") %>%
  select(id,Choice1:Choice9) %>%
  gather(Question,Response,Choice1:Choice9) %>%
  filter(!is.na(Response)) %>% 
  filter(Response!="") 

d1N <- summarise(d1,N = n_distinct(id))

stage <- count(d1,Response) %>%
  mutate(Percentage = round(n/d1N$N*100,1)) %>%
  arrange(desc(Percentage)) %>% 
  mutate(Response = factor(Response, levels=c("When researching background information for a story","When seeking to quote or otherwise directly cite an expert for a story","When seeking supplemental information for a story prior to publication","When looking for topics for a story","I only use academic research in a story when experts reach out to me to suggest or drive a story", "I do not seek out or use academic research"))) %>% 
  mutate(Response = recode(Response,"I only use academic research in a story when experts reach out to me to suggest or drive a story" = "I only use academic research in a story when experts reach out to me"))


stage_plot <- ggplot(stage, aes(x=Response, y=Percentage, fill=Response)) +
  geom_bar(stat="identity", position = position_dodge(width = 1), color="black") +
  plot_theme + coord_flip() + xlab("") +
  scale_fill_grey(start = 0, end = 0.8) + 
  scale_x_discrete(labels=c("When researching background \ninformation for a story","When seeking to quote or otherwise \ndirectly cite an expert for a story","When seeking supplemental information \nfor a story prior to publication","When looking for topics for a story","I only use academic research in a \nstory when experts reach out to \nme to suggest or drive a story", "I do not seek out or \nuse academic research")) +
  scale_y_continuous(limits=c(-1,90),expand=c(0,0)) +
  theme(legend.position="none") +
  geom_text(aes(label = Percentage), position = position_dodge(width = 0.7), hjust = -0.15, size = 3.5, color = "black") 
stage_plot
ggsave("ReplicationFile/Tierney_Graph3.png", stage_plot,dpi=300, width=7, height=3.5)


# 5. Figure 4: Responses to “How often do you seek out the results of academic research in each of the following situations?” ----------------------------------------------

Situations<-select(jdata,Q18_1,Q18_2,Q18_3,Q18_4) %>%
  gather(Question,Response,Q18_1,Q18_2,Q18_3,Q18_4) %>%
  filter(Response!="") %>% 
  mutate(Response = factor(Response, levels=c("Very often","Often","Sometimes","Rarely", "Never"))) %>%
  pctgroup(Question,Response)%>%
  mutate(Question_text = recode(Question,"Q18_1" = "When I need an outside perspective",
                                "Q18_2"="When I need more substantive expertise",
                                "Q18_3"="To provide external support",
                                "Q18_4" = "When I need to fact check claims made \nby those who hold public office"))

situations_plot <- ggplot(Situations, aes(x=Response, y=Percentage, fill=Response)) +
  geom_bar(stat="identity", position = position_dodge(width = 1), color = "black") +  
  facet_grid(Question_text~.)+
  plot_theme + coord_flip() + xlab("") +
  scale_fill_grey(start = 0, end = 0.8) +  
  scale_y_continuous(limits=c(-.5,50),expand=c(0,0)) +
  geom_text(aes(label = Percentage), position = position_dodge(width = 0.7), hjust = -0.15, size = 3.5, color = "black") 
situations_plot

ggsave("ReplicationFile/Tierney_Graph4.png",  situations_plot,dpi=300, width=8, height=6.5)

# 6. Figure 5: For your colleagues, how significant are the following potential obstacles to using academic knowledge in their work? (Grouped by significant and not significant) ----------------------------------------------

jobstacles <- select(jdata,starts_with("Q20")) %>%
  gather(Question,Response,Q20_1:Q20_7) %>%
  filter(Response!="") %>% 
  mutate(Response = recode(Response,"Not significant at all" = "Not significant",
                           "Somewhat significant" = "Significant",
                           "Very significant" = "Significant",
                           "Slightly significant" = "Not significant")) %>%
  mutate(Question_text = recode(Question,"Q20_1" = "Not enough time to follow academic work",
                                "Q20_2"="Academic work tends to be too abstract",
                                "Q20_3"="Academic work is not timely",
                                "Q20_4"="Academic work is not readily available",
                                "Q20_5"="Academic work is too jargony",
                                "Q20_6"="Academic work is too quantitative",
                                "Q20_7" = "Academic work is too focused \non internal scholarly debates"))

jobstacles<-data.frame(round(prop.table(table(jobstacles$Response,jobstacles$Question_text),2)*100,1))
names(jobstacles)<-c("Response","Question_text","Percentage")
jobstacles$Response <- factor(jobstacles$Response, c("Not significant","Significant"))
jobstacles$Question_text<-factor(jobstacles$Question_text,levels=c("Not enough time to follow academic work","Academic work is not readily available","Academic work tends to be too abstract","Academic work is not timely","Academic work is too jargony","Academic work is too focused \non internal scholarly debates","Academic work is too quantitative"))


media_obstacles<-
  ggplot(jobstacles, aes(Question_text, fill=Response)) +
  geom_bar(stat="identity", position = "stack", aes(y = Percentage), color = "black") +  
  plot_theme + coord_flip() + xlab("") +
  scale_fill_grey(start = 0, end = 0.8) +  
  scale_y_continuous(limits=c(-1,101),expand=c(0,0)) +
  guides(fill = guide_legend(reverse=TRUE))+
  geom_text(aes(label = Percentage, y = Percentage, color = factor(Response)), 
            position="stack",stat="identity",hjust =1.2,size = 3.5, 
            show.legend = FALSE) +
  scale_color_manual(values = c("white", "black")) + 
  theme(legend.position = "bottom")
media_obstacles

ggsave("ReplicationFile/Tierney_Graph5.png", media_obstacles,dpi=400, width=7, height=4)

# 7. Figure 6: Responses to “How important are the following sources of information to the work you do as a journalist?” ----------------------------------------------

medium <- select(jdata,starts_with("Q19")) %>%
  gather(Question,Response,Q19_1:Q19_8) %>%
  filter(Response!="") %>%
  mutate(Response = recode(Response,"Not important at all" = "Not important",
                           "Not very important" = "Not important",
                           "Very important" = "Important",
                           "Somewhat important"="Important")) %>%
  mutate(Question_text = recode(Question,"Q19_1" = "Academic books and articles",
                                "Q19_2" = "Policy journal articles",
                                "Q19_3" = "Newspapers and magazines",
                                "Q19_4" = "Think tank and NGO reports",
                                "Q19_5" = "Blogs and online research",
                                "Q19_6" = "Television and radio",
                                "Q19_7" = "Social media",
                                "Q19_8" = "Interviews with academic experts"))
medium$Response<-factor(medium$Response, levels=c("Not important","Important"))
medium<-data.frame(round(prop.table(table(medium$Response,medium$Question_text),2)*100,1))
names(medium)<-c("Response","Media","Percentage")

medium$Media<-factor(medium$Media,levels=c("Television and radio",
                                           "Blogs and online research",
                                           "Academic books and articles",
                                           "Social media",
                                           "Interviews with academic experts",
                                           "Policy journal articles",
                                           "Think tank and NGO reports",
                                           "Newspapers and magazines"))

medium_plot<-
  ggplot(medium, aes(x=Media, fill=Response)) +
  geom_bar(position = "stack", aes(y = Percentage), stat = "identity", color = "black") + 
  plot_theme + coord_flip() + xlab("") + ylab("") +
  scale_fill_grey(start = 0, end = 0.8) +
  guides(fill = guide_legend(reverse=TRUE))+
  scale_y_continuous(limits=c(-5,102),expand=c(0,0))+
  scale_y_continuous(limits=c(-5,102),expand=c(0,0)) +
   geom_text(aes(y = Percentage, label = Percentage, color = factor(Response)), 
            stat = "identity", position = position_stack(vjust = .05), hjust = 0, size = 3.5, 
            show.legend = FALSE) +
  scale_color_manual(values = c("white", "black")) + 
  theme(legend.position = "bottom")
medium_plot
ggsave("ReplicationFile/Tierney_Graph6.png", medium_plot,dpi=300,width=7,height=4)

# 8. Figure 7: Effect of high consensus treatment split by scholar type ----------------------------------------------

#regression form of IR expert experiment 
jdata$ir_balance_dv<-as.numeric(jdata$media_balance_1)
jdata$IR_Scholar_Percent<-as.factor(jdata$Scholar_Percent)
levels(jdata$IR_Scholar_Percent)<-c(0,1)
IR_experiment <- lm(ir_balance_dv~IR_Scholar_Percent, data=jdata)
stargazer(IR_experiment)

#regression form of econ expert experiment 
jdata$econ_balance_dv<-as.numeric(jdata$Q52_1)
jdata$econ_Scholar_Percent<-as.factor(jdata$Scholar_Percent_econ)
levels(jdata$econ_Scholar_Percent)<-c(0,1)
econ_experiment <- lm(econ_balance_dv~econ_Scholar_Percent, data=jdata)
stargazer(econ_experiment)

#experiment visualization
temp_df <- rbind(as.data.frame(coef(summary(IR_experiment))),as.data.frame(coef(summary(econ_experiment))))
temp_df$iv <- rownames(temp_df)
temp_df$upper95 <- temp_df$Estimate + 1.96*temp_df$"Std. Error"
temp_df$lower95 <- temp_df$Estimate - 1.96*temp_df$"Std. Error"
temp_df$upper90 <- temp_df$Estimate + 1.645*temp_df$"Std. Error"
temp_df$lower90 <- temp_df$Estimate - 1.645*temp_df$"Std. Error"
temp_df <- subset(temp_df, iv!="(Intercept)")
temp_df <- subset(temp_df, iv!="(Intercept)1")
temp_df$iv_formatted <- ""
temp_df[temp_df$iv == "IR_Scholar_Percent1",]$iv_formatted <- "International Relations\nScholars"
temp_df[temp_df$iv == "econ_Scholar_Percent1",]$iv_formatted <- "Economics Scholars"

experiment_results <- ggplot(data=temp_df, aes(x=iv_formatted)) + 
  geom_hline(yintercept=0, color="grey50", linetype="dashed", size=.5) +
  geom_errorbar(aes(ymin=lower95, ymax=upper95, width=.0), size=.4, position=position_dodge(width=-1)) +
  geom_point(aes(y=Estimate), size=2) + 
  xlab("Discipline treatment") +
  ylab("Estimated treatment\neffect of high consensus") +
  scale_x_discrete(limits = rev(levels(temp_df$iv_formatted)))+
  plot_theme +
  theme(axis.title.y = element_text(angle=0))
experiment_results
ggsave("ReplicationFile/Tierney_Graph7.png", experiment_results, dpi=300, width=7, height=4)

# 9. Figure 8: Distribution of responses to media balancing experiment by consensus treatment and scholar type ----------------------------------------------

jdata_ir<-jdata %>% select(Scholar_Percent,ir_balance_dv)
jdata_econ<-jdata %>% select(Scholar_Percent_econ,econ_balance_dv)
jdata_ir$field<-"International Relations scholars"
jdata_econ$field<-"Economics scholars"

names(jdata_econ)<-c("percent","balance_dv","field")
names(jdata_ir)<-c("percent","balance_dv","field")

jdata_mean<-rbind(jdata_ir,jdata_econ) %>%
  group_by(field,percent) %>%
  summarise(sem = sd(balance_dv,na.rm=TRUE)/sqrt(length(balance_dv)),  # Standard error of the mean (SEM)
            ci.low = (mean(balance_dv,na.rm=TRUE) - 2*sem),
            ci.upp = (mean(balance_dv,na.rm=TRUE) + 2*sem),
            n=mean(balance_dv,na.rm=TRUE))
jdata_mean

density_distribution<-ggplot(rbind(jdata_ir,jdata_econ),aes(x=balance_dv,fill=as.factor(percent))) +
  geom_density(alpha=.3,adjust=2) +
  scale_x_continuous(limits=c(0,100),labels=paste(c(0,25,50,75,100),sep=""),name="Percentage of sources in favor of consensus") +
  scale_y_continuous(limits=c(0,.07)) +
  scale_fill_manual(values = c("grey75", "grey25"),
                    labels = c("52% agreement", "93% agreement")) + 
  scale_color_manual(values = c("black", "black")) + 
  facet_grid(rows=vars(field)) +
  ylab("Density") +
  theme_bw() +
  labs(fill = "Treatment") +  # Set legend title
  theme(legend.position = "right") 
density_distribution

ggsave("ReplicationFile/Tierney_Graph8.png", density_distribution, dpi=300, width=8, height=4.5)

